package alvarodelrosal.chat.server.modelo.chataction;

import alvarodelrosal.chat.server.infraestructura.ChatLiveConversations;
import alvarodelrosal.chat.server.modelo.ChatConnection;
import alvarodelrosal.chat.server.modelo.ChatConversation;
import java.util.List;

public class ChatMyChats implements ChatAction {

    @Override
    public String getName() {
        return "MyChats";
    }

    @Override
    public boolean needsAdminPrivileges() {
        return false;
    }

    @Override
    public boolean needsLogin() {
        return true;
    }

    @Override
    public String doAction(ChatConnection connection, List<String> parameters) {
        StringBuilder builder = new StringBuilder("MyChats");
        List<ChatConversation> conversationsWith = ChatLiveConversations.getConversationsWith(
                connection.whoAmI().getUserId());
        
        for(ChatConversation conversation : conversationsWith) {
            builder.append("<:@:>");
            builder.append(conversation.getId());
        }
        
        return builder.toString();
    }
    
}
